package demo02;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class DouDiZhu {
	public static void main(String[] args) {
		ArrayList<String> poker=new ArrayList<>();
		Map<String, Integer> map=new HashMap<>();
		String[] colors={"♠","♣","♦","♥"};
		String[] numbers={"2","A","K","Q","J","10","9","8","7","6","5","4","3"};
		poker.add("大王");
		poker.add("小王");
		for(String number:numbers){
			for(String color:colors){
				poker.add(color+number);
			}
		}
		int count=1;
		for(String pokers:poker){
			map.put(pokers, count);
			count++;
		}
		System.out.println(poker);
		Collections.shuffle(poker);
		System.out.println(poker);
		System.out.println("---------");
		Player p1 = new Player("老王");
		Player p2 = new Player("老李");
		Player p3 = new Player("老六");
		ArrayList<String> dipai=new ArrayList<>();
		for(int i=0;i<poker.size();i++){
			String p = poker.get(i);
			if(i>=51){
				dipai.add(p);
			}else if(i%3==0){
				p1.getPoker().add(p);
			}else if(i%3==1){
				p2.getPoker().add(p);
			}else if(i%3==2){
				p3.getPoker().add(p);
			}
		}
		Map<String, Integer> map1=new HashMap<>();
		p1.getPoker().forEach(s->map1.put(s, map.get(s)));
		List<Map.Entry<String, Integer>> list = new ArrayList<Map.Entry<String, Integer>>(map1.entrySet());
		Collections.sort(list,(o1,o2)->o2.getValue().compareTo(o1.getValue()));
		System.out.print(p1.getName()+":");
		list.forEach(s->System.out.print(s.getKey()+" "));
		System.out.println();
		Map<String, Integer> map2=new HashMap<>();
		p2.getPoker().forEach(s->map2.put(s, map.get(s)));
		List<Map.Entry<String, Integer>> list1 = new ArrayList<Map.Entry<String, Integer>>(map2.entrySet());
		Collections.sort(list1,(o1,o2)->o2.getValue().compareTo(o1.getValue()));
		System.out.print(p2.getName()+":");
		list1.forEach(s->System.out.print(s.getKey()+" "));
		System.out.println();
		Map<String, Integer> map3=new HashMap<>();
		p3.getPoker().forEach(s->map3.put(s, map.get(s)));
		List<Map.Entry<String, Integer>> list2 = new ArrayList<Map.Entry<String, Integer>>(map3.entrySet());
		Collections.sort(list2,(o1,o2)->o2.getValue().compareTo(o1.getValue()));
		System.out.print(p3.getName()+":");
		list2.forEach(s->System.out.print(s.getKey()+" "));
		System.out.println();
	}
}
